import {onlineModule} from './online'
import {authModule} from './auth'
import {userModule} from './user'
import {universityModule} from "./university";
import cookies from '../cookie/cookies'
import {hsModule} from "./hs";
import memberInfo from './memberInfo'
import courseInfo from './courseInfo';

Vue.use(Vuex);

const store = new Vuex.Store(
  {
    strict: process.env.NODE_ENV !== 'production',
    modules: {
      hs: hsModule,
      online: onlineModule,
      auth: authModule,
      user: userModule,
      university: universityModule,
      memberInfo,
      courseInfo,
      page: {
        namespaced: true,

      },
    }
  });

export default store

///获取字段的数据，如果是空，则在cookie中获取，返回值不为空
export function getStateData(state, field, key, mutationType) {
  if (!state[field]) {
    let cacheVal = cookies.get(key);
    store.commit(mutationType, cacheVal);
    return cacheVal || {}
  }
  return state[field] || {}
}

